<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<!--css样式  -->
<link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/carts.css">
</head>
<body>
<jsp:include page="header.jsp"></jsp:include>
<section class="cartMain">
        <div class="cartMain_hd">
            <ul class="order_lists cartTop">
                <li class="list_chk">
                    <!--所有商品全选-->
                    <input type="checkbox" id="all" class="whole_check">
                    <label for="all"></label>全选
                </li>
                <li class="list_con">商品信息</li>
                <li class="list_info">尺寸</li>
                <li class="list_price">单价</li>
                <li class="list_amount">数量</li>
                <li class="list_sum">金额</li>
                <li class="list_op">操作</li>
            </ul>
        </div>

        <div class="cartBox">
            <div class="order_content">
            <c:choose>
		        <c:when test="${empty shopcart }"></c:when>
		        <c:otherwise>
		            <c:forEach items="${shopcart }" var="s" varStatus="xh">
			            <ul class="order_lists">
		                    <li class="list_chk">
		                        <input type="checkbox" id="checkbox_${xh.count}" class="son_check" value="${s.id }">
		                        <label for="checkbox_${xh.count}"></label>
		                    </li>
		                    <li class="list_con">
		                        <div class="list_img"><a href="javascript:;"><img src="${s.pimg}" alt=""></a></div>
		                        <div class="list_text"><a href="javascript:;">${s.pname}</a></div>
		                    </li>
		                    <li class="list_info">
		                        <p>${s.size}</p>
		                    </li>
		                    <li class="list_price">
		                        <p class="price">￥${s.price}</p>
		                    </li>
		                    <li class="list_amount">
		                        <div class="amount_box">
		                            <a href="javascript:changeCount('sub',${s.id});" class="reduce reSty">-</a>
		                            <input type="text" value="${s.count}" class="sum" readOnly="true">
		                            <a href="javascript:changeCount('add',${s.id});" class="plus">+</a>
		                        </div>
		                    </li>
		                    <li class="list_sum">
		                        <p class="sum_price">￥${s.totalprice}</p>
		                    </li>
		                    <li class="list_op">
		                        <p class="del"><a href="javascript:;" orderId="${s.id }"  class="delBtn">移除商品</a></p>
		                    </li>
		                </ul>
		            </c:forEach>
		        </c:otherwise>
	        </c:choose>
            </div>
        </div>
        <!--底部-->
        <div class="bar-wrapper">
            <div class="bar-right">
                <div class="piece">已选商品<strong class="piece_num">0</strong>件</div>
                <div class="totalMoney">共计: <strong class="total_text">0.00</strong></div>
                <div class="calBtn"><a href="javascript:toOrder();" class="count">结算</a></div>
            </div>
        </div>
    </section>
    <section class="model_bg"></section>
    <section class="my_model">
        <p class="title">删除宝贝<span class="closeModel">X</span></p>
        <p>您确认要删除该宝贝吗？</p>
        <div class="opBtn"><a href="javascript:;" class="dialog-sure">确定</a><a href="javascript:;" class="dialog-close">关闭</a></div>
    </section>
	
    <script src="js/jquery.min.js"></script>
    <script src="js/carts.js"></script>

	<script type="text/javascript">
		/* 加减数量 */
		function changeCount(option,id){
			$.ajax({
				type: 'post',
				url: 'upShopcart.do',
				data:{"id":id,"option":option},
				dataType:'json',
				success:function(data){
					
				},
				error:function(){
					alert("操作失败！！！")
				}
			});
		}
		/* 移除产品 */
		/*function delShopcart(id){
			if(confirm("确定删除")){
				
				
				
				$.ajax({
					type: 'post',
					url: 'delShopcart.do',
					data:{"id":id},
					dataType:'json',
					success:function(data){
						
					},
					error:function(){
						alert("操作失败！！！")
					}
				})
			}
			
		}*/

		 /* 跳转到订单页 */
		function toOrder(){
			 var ids = [];
			 $("input[type='checkbox']").each(function(){  
				 var sc= $(this).hasClass("son_check");
				 if(sc){
					 if(this.checked==true){
						 ids.push($(this).val())
		             }  
			     }
	         });
	         //拼接id(把数组转成字符串，并且用逗号拼接),比如ids=[2,5,6]，那么id='2,5,6'
	         var idStr = ids.join(',');
	         location.href="toOrder.do?ids="+ids
		}
	</script>
	


</body>
</html>